/*
 * SquareHandle.java
 *
 * Created on 19 maart 2008, 9:45
 *
 * @author wijnand.schepens@hogent.be
 */
package diagram.handles;

import diagram.Node;
import diagram.locations.Location;
import diagram.locations.LowerRightLocation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class SquareHandle extends Handle {

    protected int size;	// size of the square

    public SquareHandle() {
    }

    public SquareHandle(Node baseNode, Location location, int size) {
        super(baseNode, location);
        this.size = size;

    }

    public void setLocation(Location location) {
        super.setLocation(location);
    }

    public void setSize(int size) {
        this.size = size;
    }

    public void paint(Graphics2D g) {
        Color oldColor = g.getColor();

        g.setColor(Color.WHITE);
        g.fill(this.getRectangle());
        g.setColor(Color.BLACK);
        g.draw(this.getRectangle());
        if (this.isHighlighted()) {
            g.draw(this.getHighlightRectangle());
        }

        g.setColor(oldColor);
    }

    public boolean contains(int x, int y) {
        return this.getRectangle().contains(x, y);
    }

    public boolean isContainedIn(Rectangle rect) {
        return rect.contains(this.getRectangle());
    }

    protected Rectangle getRectangle() {
        return new Rectangle(getLocation().getX() - size / 2, getLocation().getY() - size / 2, size, size);
    }

    protected Rectangle getHighlightRectangle() {
        return new Rectangle(getLocation().getX() - (size / 2 + 2), getLocation().getY() - (size / 2 + 2), size + 4, size + 4);
    }
}
